<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\agent;

use App\Dao\AgentBankDao;
use App\Service\Agent\PartnerService;
use App\Service\Agent\RegionService;
use App\Middleware\User\AgentMiddleware;
use App\Request\Agent\User\PartnerAddRequest;

use App\Service\Agent\StoreService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 合伙人控制器
 *
 * @AutoController()
 * @Middleware(AgentMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\admin
 */
class PartnerController extends Controller
{

    /**
     * @Inject
     * @var PartnerService
     */
    public $partner_service;

    /**
     * @Inject
     * @var StoreService
     */
    public $store_service;

    /**
     * 合伙人列表
     */
    public function list()
    {
        $result = $this->partner_service->list();

        $this->success($result);
    }

    /**
     * 合伙人详情
     */
    public function details()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $result = $this->partner_service->details($agent_id);

        $this->success($result);
    }

    /**
     * 合伙人市代列表
     */
    public function partnerCityList()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $result = $this->partner_service->partnerCityList($agent_id);

        $this->success($result);
    }

    /**
     * 合伙人区代列表
     */
    public function partnerAreaList()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $result = $this->partner_service->partnerAreaList($agent_id);

        $this->success($result);
    }

    /**
     * 合伙人渠道商列表
     */
    public function partnerChannelList()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $result = $this->partner_service->partnerChannelList($agent_id);

        $this->success($result);
    }

    /**
     * 新增合伙人
     * @param PartnerAddRequest $request
     */
    public function add(PartnerAddRequest $request)
    {
        $params = $request->all();

        $result = $this->partner_service->add($params);

        $this->success($result);
    }

    /**
     * 查询合伙人 单条数据
     */
    public function getPartnerFirst()
    {
        $partner_id = (int)$this->request->input('partner_id', 0);

        $result = $this->partner_service->agent_dao->first($partner_id);

        $this->success($result);
    }

    /**
     * 删除合伙人
     */
    public function deletePartner()
    {
        $partner_id = (int)$this->request->input('partner_id', 0);

        $result = $this->partner_service->deletePartner($partner_id);

        $this->success($result);
    }

    /**
     * 调整合伙人状态
     */
    public function setPartnerStatus()
    {
        $partner_id = (int)$this->request->input('partner_id', 0);

        $result = $this->partner_service->setPartnerStatus($partner_id);

        $this->success($result);
    }

    /**
     * 重置合伙人市代\区代密码
     */
    public function resetPasswordById()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $partner_id = (int)$this->request->input('partner_id', 0);

        $result = $this->store_service->resetPasswordById( $agent_id, $partner_id );

        $this->success( $result );
    }

    /**
     * 删除合伙人区代\市代
     */
    public function deleteAreaCityAgent()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $partner_id = (int)$this->request->input('partner_id', 0);

        $result = $this->store_service->deleteAreaCityAgent( $agent_id, $partner_id );

        $this->success( $result );
    }

    /**
     * 调整合伙人区代\市代的状态
     */
    public function setAreaCityStatus()
    {
        $agent_id = (int)$this->request->input('agent_id', 0);

        $partner_id = (int)$this->request->input('partner_id', 0);

        $result = $this->store_service->setAreaCityStatus( $agent_id, $partner_id );

        $this->success( $result );
    }

    /**
     * 获取分公司直招的合伙人
     */
    public function getOfficePartner()
    {
        $result = $this->partner_service->getOfficePartner();

        $this->success($result);
    }

    /**
     * 获取分公司直招的市代
     */
    public function getOfficeCity()
    {
        $result = $this->partner_service->getOfficeCity();

        $this->success($result);
    }

    /**
     * 获取分公司直招的区代
     */
    public function getOfficeArea()
    {
        $result = $this->partner_service->getOfficeArea();

        $this->success($result);
    }
}